





<!DOCTYPE html>
<html class="writer-html5" lang="zh-CN" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>tvm.relay.frontend &mdash; tvm 0.8.dev1982 文档</title>
  

  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/css/tlcpack_theme.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../../../_static/tvm-logo-square.png"/>
  

  
  
  
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
        <script data-url_root="../../../../" id="documentation_options" src="../../../../_static/documentation_options.js"></script>
        <script src="../../../../_static/jquery.js"></script>
        <script src="../../../../_static/underscore.js"></script>
        <script src="../../../../_static/doctools.js"></script>
        <script src="../../../../_static/translations.js"></script>
    
    <script type="text/javascript" src="../../../../_static/js/theme.js"></script>

    
    <script type="text/javascript" src="../../../../_static/js/tlcpack_theme.js"></script>
    <link rel="index" title="索引" href="../../../../genindex.html" />
    <link rel="search" title="搜索" href="../../../../search.html" />
    <link rel="next" title="tvm.relay.nn" href="nn.html" />
    <link rel="prev" title="tvm.relay" href="index.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    
<header class="header">
    <div class="innercontainer">
      <div class="headerInner d-flex justify-content-between align-items-center">
          <div class="headerLogo">
               <a href="https://tvm.apache.org/"><img src=https://tvm.apache.org/assets/images/logo.svg alt="logo"></a>
          </div>

          <div id="headMenu" class="headerNav">
            <button type="button" id="closeHeadMenu" class="navCloseBtn"><img src="../../../../_static/img/close-icon.svg" alt="Close"></button>
             <ul class="nav">
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/community>Community</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/download>Download</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/vta>VTA</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/blog>Blog</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/docs>Docs</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmconf.org>Conference</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://github.com/apache/tvm/>Github</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmchinese.github.io/declaration_zh_CN.html>About-Translators</a>
                </li>
             </ul>
               <div class="responsivetlcdropdown">
                 <button type="button" class="btn-link">
                   ASF
                 </button>
                 <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                 </ul>
               </div>
          </div>
            <div class="responsiveMenuIcon">
              <button type="button" id="menuBtn" class="btn-menu"><img src="../../../../_static/img/menu-icon.svg" alt="Menu Icon"></button>
            </div>

            <div class="tlcDropdown">
              <div class="dropdown">
                <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  ASF
                </button>
                <div class="dropdown-menu dropdown-menu-right">
                  <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                  </ul>
                </div>
              </div>
          </div>
       </div>
    </div>
 </header>
 
    <nav data-toggle="wy-nav-shift" class="wy-nav-side fixed">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../../index.html">
          

          
            
            <img src="../../../../_static/tvm-logo-small.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
                <div class="version">
                  0.8.dev1982
                </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption" role="heading"><span class="caption-text">如何开始</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../install/index.html">安装 TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../contribute/index.html">贡献者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">用户引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../tutorial/index.html">User Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../how_to/index.html">How To Guides</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">开发者引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../dev/tutorial/index.html">Developer Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../dev/how_to/how_to.html">开发者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">架构指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../arch/index.html">Design and Architecture</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">主题引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../topic/microtvm/index.html">microTVM：裸机使用TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../topic/vta/index.html">VTA: Versatile Tensor Accelerator</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">参考指南</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../langref/index.html">语言参考</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">Python API</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../runtime.html">tvm.runtime</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ndarray.html">tvm.runtime.ndarray</a></li>
<li class="toctree-l2"><a class="reference internal" href="../error.html">tvm.error</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ir.html">tvm.ir</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ir.html#module-tvm.instrument">tvm.instrument</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ir.html#module-tvm.transform">tvm.transform</a></li>
<li class="toctree-l2"><a class="reference internal" href="../target.html">tvm.target</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tir.html">tvm.tir</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tir.html#module-tvm.tir.transform">tvm.tir.transform</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tir.html#tvm-tir-analysis">tvm.tir.analysis</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tir.html#module-tvm.tir.stmt_functor">tvm.tir.stmt_functor</a></li>
<li class="toctree-l2"><a class="reference internal" href="../te.html">tvm.te</a></li>
<li class="toctree-l2"><a class="reference internal" href="../te.html#module-tvm.te.hybrid">tvm.te.hybrid</a></li>
<li class="toctree-l2"><a class="reference internal" href="../driver.html">tvm.driver</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html">tvm.relay</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">tvm.relay.frontend</a></li>
<li class="toctree-l2"><a class="reference internal" href="nn.html">tvm.relay.nn</a></li>
<li class="toctree-l2"><a class="reference internal" href="vision.html">tvm.relay.vision</a></li>
<li class="toctree-l2"><a class="reference internal" href="image.html">tvm.relay.image</a></li>
<li class="toctree-l2"><a class="reference internal" href="transform.html">tvm.relay.transform</a></li>
<li class="toctree-l2"><a class="reference internal" href="analysis.html">tvm.relay.analysis</a></li>
<li class="toctree-l2"><a class="reference internal" href="backend.html">tvm.relay.backend</a></li>
<li class="toctree-l2"><a class="reference internal" href="dataflow_pattern.html">tvm.relay.dataflow_pattern</a></li>
<li class="toctree-l2"><a class="reference internal" href="testing.html">tvm.relay.testing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../autotvm.html">tvm.autotvm</a></li>
<li class="toctree-l2"><a class="reference internal" href="../auto_scheduler.html">tvm.auto_scheduler</a></li>
<li class="toctree-l2"><a class="reference internal" href="../rpc.html">tvm.rpc</a></li>
<li class="toctree-l2"><a class="reference internal" href="../micro.html">tvm.micro</a></li>
<li class="toctree-l2"><a class="reference internal" href="../contrib.html">tvm.contrib</a></li>
<li class="toctree-l2"><a class="reference internal" href="../graph_executor.html">tvm.contrib.graph_executor</a></li>
<li class="toctree-l2"><a class="reference internal" href="../topi.html">tvm.topi</a></li>
<li class="toctree-l2"><a class="reference internal" href="../vta/index.html">vta</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../links.html">Other APIs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../publications.html">Publications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../genindex.html">索引</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
      
      <nav class="wy-nav-top" aria-label="top navigation" data-toggle="wy-nav-top">
        
            <div class="togglemenu">

            </div>
            <div class="nav-content">
              <!-- tvm -->
              Table of content
            </div>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        

          




















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../../index.html">Docs</a> <span class="br-arrow">></span></li>
        
          <li><a href="../index.html">Python API</a> <span class="br-arrow">></span></li>
        
      <li>tvm.relay.frontend</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../../../../_sources/reference/api/python/relay/frontend.rst.txt" rel="nofollow"> <img src="../../../../_static//img/source.svg" alt="viewsource"/></a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="module-tvm.relay.frontend">
<span id="tvm-relay-frontend"></span><h1>tvm.relay.frontend<a class="headerlink" href="#module-tvm.relay.frontend" title="永久链接至标题">¶</a></h1>
<p>用于构建 Relay 程序的前端。</p>
<p>包含当前为 Relay 定义的模型导入器。</p>
<p><strong>函数：</strong></p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_mxnet" title="tvm.relay.frontend.from_mxnet"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_mxnet</span></code></a>(symbol[, shape, dtype, …])</p></td>
<td><p>将 MXNet 的模型转换为兼容的relay Function。</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#tvm.relay.frontend.quantize_conv_bias_mkldnn_from_var" title="tvm.relay.frontend.quantize_conv_bias_mkldnn_from_var"><code class="xref py py-obj docutils literal notranslate"><span class="pre">quantize_conv_bias_mkldnn_from_var</span></code></a>(bias_var, …)</p></td>
<td><p>量化的conv2d偏置</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_keras" title="tvm.relay.frontend.from_keras"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_keras</span></code></a>(model[, shape, layout])</p></td>
<td><p>将Keras模型转换为对应的relay Function。</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_onnx" title="tvm.relay.frontend.from_onnx"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_onnx</span></code></a>(model[, shape, dtype, opset, …])</p></td>
<td><p>将一个ONNX模型转化为一个等价的Relay Function。</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_tflite" title="tvm.relay.frontend.from_tflite"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_tflite</span></code></a>(model[, shape_dict, dtype_dict])</p></td>
<td><p>将 tflite 的模型转换为对应的 relay Function。</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_coreml" title="tvm.relay.frontend.from_coreml"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_coreml</span></code></a>(model[, shape])</p></td>
<td><p>将coreml模型转换为对应的relay Function。</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_caffe2" title="tvm.relay.frontend.from_caffe2"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_caffe2</span></code></a>(init_net, predict_net[, shape, …])</p></td>
<td><p>将包含init_net和predict_net的caffe2模型转换为Relay Function。</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_tensorflow" title="tvm.relay.frontend.from_tensorflow"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_tensorflow</span></code></a>(graph[, layout, shape, …])</p></td>
<td><p>加载一个从python tensorflow计算图转换而来的relay。模型配套的参数将被自动处理。</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_darknet" title="tvm.relay.frontend.from_darknet"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_darknet</span></code></a>(net[, shape, dtype])</p></td>
<td><p>将Darknet模型转换为对应的relay Function。</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_pytorch" title="tvm.relay.frontend.from_pytorch"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_pytorch</span></code></a>(script_module, input_infos[, …])</p></td>
<td><p>使用torchsrcipt形式加载PyTorch模型，并将其转换为对应的relay。</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_caffe" title="tvm.relay.frontend.from_caffe"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_caffe</span></code></a>(init_net, predict_net, …)</p></td>
<td><p>将caffe模型转换为对应的relay Function。</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#tvm.relay.frontend.from_paddle" title="tvm.relay.frontend.from_paddle"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_paddle</span></code></a>(program_or_layer[, shape_dict, …])</p></td>
<td><p>将PaddlePaddle模型转换为对应的Relay Function。</p></td>
</tr>
</tbody>
</table>
<p><strong>类：</strong></p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="#tvm.relay.frontend.ChangeDatatype" title="tvm.relay.frontend.ChangeDatatype"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ChangeDatatype</span></code></a>(src, dst)</p></td>
<td><p>需要改变Relay中数据类型时的应变手段。</p></td>
</tr>
</tbody>
</table>
<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_mxnet">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_mxnet</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symbol</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dtype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'float32'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg_params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">aux_params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_mxnet" title="永久链接至目标">¶</a></dt>
<dd><p>将 MXNet 的模型转换为兼容的relay Function。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>symbol</strong> (<em>mxnet.Symbol</em><em> or </em><em>mxnet.gluon.HybridBlock</em>) – MXNet模型标志。</p></li>
<li><p><strong>shape</strong> (<em>dict of str to tuple</em><em>, </em><em>optional</em>) – 计算图输入节点的数据形状</p></li>
<li><p><strong>dtype</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a><em> or </em><em>dict of str to str</em>) – 计算图输入节点的数据类型</p></li>
<li><p><strong>arg_params</strong> (<em>dict of str to mx.NDArray</em>) – mxnet中的模型参数</p></li>
<li><p><strong>aux_params</strong> (<em>dict of str to mx.NDArray</em>) – mxnet中的辅助参数</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The relay module for compilation</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.nd.NDArray</em>) – The parameter dict to be used by nnvm</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.quantize_conv_bias_mkldnn_from_var">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">quantize_conv_bias_mkldnn_from_var</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">bias_var</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bias_scale</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.quantize_conv_bias_mkldnn_from_var" title="永久链接至目标">¶</a></dt>
<dd><p>量化的conv2d偏置</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_keras">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_keras</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">model</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">layout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'NCHW'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_keras" title="永久链接至目标">¶</a></dt>
<dd><p>将Keras模型转换为对应的relay Function。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>model</strong> (<em>keras.engine.training.Model</em><em> or </em><em>tensorflow.keras.models.Model</em>) – 将要被转换的keras模型。</p></li>
<li><p><strong>shape</strong> (<em>dict of str to int list/tuple</em>) – 模型输入节点的数据形状，可选</p></li>
<li><p><strong>layout</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a>) – “NCHW” 或 “NHWC”之一，表示数据在输出模型中应如何排列。默认布局是’NCHW’，因为一般来说，它在TVM中表现得更好。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The relay module for compilation.</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.nd.NDArray</em>) – The parameter dict to be used by Relay.</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_onnx">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_onnx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">model</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dtype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'float32'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">opset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">freeze_params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">convert_config</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_onnx" title="永久链接至目标">¶</a></dt>
<dd><p>将一个ONNX模型转化为一个等价的Relay Function。</p>
<p>被解析为 Python Protobuf 对象的ONNX 计算图。模型配套的参数将被自动处理。然而，来自ONNX计算图的输入名称是模糊的，混合了输入和网络权重/偏置，如 “1”、”2”… 为方便起见，我们将 “真实” 的输入名称重命名为 “input_0”, “input_1”… 并将参数重命名为 “param_0”、”param_1”…</p>
<p>默认情况下，ONNX 以动态图的方式定义模型。ONNX 导入器在导入时保留了这种动态性，而编译器则试图在编译时将模型转换为静态形状。如果转换失败，则代表模型中可能仍有动态操作。目前并非所有的TVM内核都支持动态形状，如果你在使用动态内核时遇到错误，请在discussion.tvm.apache.org上提交问题。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>model</strong> (<em>protobuf object</em>) – ONNX v1.1.0之后的ONNX ModelProto</p></li>
<li><p><strong>shape</strong> (<em>dict of str to tuple</em><em>, </em><em>optional</em>) – 计算图输入节点的数据形状</p></li>
<li><p><strong>dtype</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a><em> or </em><em>dict of str to str</em>) – 计算图输入节点的数据类型</p></li>
<li><p><strong>opset</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.10)"><em>int</em></a><em>, </em><em>optional</em>) – 自定义优化等级，并覆盖掉程序自动检测的优化等级结果。这对一些测试是有帮助的。</p></li>
<li><p><strong>freeze_params</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.10)"><em>bool</em></a>) – 如果这个参数为True，转换脚本将接受所有被用户提供的onnx输入值（权重、形状等），并将它们定义为常量而不是变量、嵌入到relay中。如果某些输入能在编译时被relay认为是常量，那么就可以用这个方法，这将使得模型在转换时得到更深层次的优化</p></li>
<li><p><strong>convert_config</strong> (<em>Optional</em><em>[</em><a class="reference internal" href="dataflow_pattern.html#tvm.relay.dataflow_pattern.Dict" title="tvm.relay.dataflow_pattern.Dict"><em>Dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a><em>, </em><a class="reference internal" href="../tir.html#tvm.tir.Any" title="tvm.tir.Any"><em>Any</em></a><em>]</em><em>]</em>) – <dl class="simple">
<dt>默认的配置：</dt><dd><dl class="simple">
<dt>use_nt_batch_matmul<span class="classifier">bool = True</span></dt><dd><p>True to convert qualified onnx <cite>matmul</cite> to <cite>nn.batch_matmul</cite> strict to NT format
(transpose_a=False, transpose_b=True).</p>
</dd>
</dl>
</dd>
</dl>
</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The relay module for compilation</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.nd.NDArray</em>) – The parameter dict to be used by relay</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_tflite">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_tflite</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">model</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape_dict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dtype_dict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_tflite" title="永久链接至目标">¶</a></dt>
<dd><p>将 tflite 的模型转换为对应的 relay Function。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>model</strong> – tflite.Model or tflite.Model.Model （由所使用的tflite版本决定）</p></li>
<li><p><strong>shape_dict</strong> (<em>dict of str to int list/tuple</em>) – 模型输入节点的数据形状。</p></li>
<li><p><strong>dtype_dict</strong> (<em>dict of str to str</em>) – 模型输入节点的数据类型。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The relay module for compilation.</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.nd.NDArray</em>) – The parameter dict to be used by relay</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_coreml">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_coreml</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">model</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_coreml" title="永久链接至目标">¶</a></dt>
<dd><p>将coreml模型转换为对应的relay Function。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>model</strong> – coremltools.models.MLModel of a NeuralNetworkClassifier</p></li>
<li><p><strong>shape</strong> (<em>dict of str to int list/tuple</em><em>, </em><em>optional</em>) – 输入节点大小</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The relay module for compilation.</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.nd.NDArray</em>) – The parameter dict to be used by Relay.</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_caffe2">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_caffe2</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">init_net</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">predict_net</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dtype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'float32'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_caffe2" title="永久链接至目标">¶</a></dt>
<dd><p>将包含init_net和predict_net的caffe2模型转换为Relay Function。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>init_net</strong> (<em>protobuf object</em>) – 包含权重的Caffe2 NetDef</p></li>
<li><p><strong>predict_net</strong> (<em>protobuf object</em>) – 包含计算图的Caffe2 NetDef</p></li>
<li><p><strong>shape</strong> (<em>dict of str to tuple</em>) – 计算图输入节点的数据形状</p></li>
<li><p><strong>dtype</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a><em> or </em><em>dict of str to str</em>) – 计算图输入节点的数据类型</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The module that optimizations will be performed on.</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.nd.NDArray</em>) – Dict of converted parameters stored in tvm.nd.NDArray format</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_tensorflow">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_tensorflow</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">graph</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">layout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'NHWC'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">outputs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">convert_config</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_tensorflow" title="永久链接至目标">¶</a></dt>
<dd><p>加载一个从python tensorflow计算图转换而来的relay。模型配套的参数将被自动处理。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>graph</strong> (<em>GraphDef object</em>) – Tensorflow GraphDef</p></li>
<li><p><strong>layout</strong> (<em>target layout to be used</em><em> (</em><em>Optional</em><em>)</em>) – 现在该参数仅支持NCHW，以便在GPU上启用NHWC模式。</p></li>
<li><p><strong>shape</strong> (<em>Dictionary of input dimensions</em><em> (</em><em>Optional</em><em>)</em>) – 由计算图的输入节点形状组成的字典。</p></li>
<li><p><strong>outputs</strong> (<em>List of output tensor names</em><em> (</em><em>Optional</em><em>)</em>) – 如果该参数没有被指定，那么输入计算图的最后一个节点将被假定为图的输出。</p></li>
<li><p><strong>convert_config</strong> (<em>Optional</em><em>[</em><a class="reference internal" href="dataflow_pattern.html#tvm.relay.dataflow_pattern.Dict" title="tvm.relay.dataflow_pattern.Dict"><em>Dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a><em>, </em><a class="reference internal" href="../tir.html#tvm.tir.Any" title="tvm.tir.Any"><em>Any</em></a><em>]</em><em>]</em>) – <dl class="simple">
<dt>默认的配置：</dt><dd><dl class="simple">
<dt>use_dense<span class="classifier">bool = True</span></dt><dd><p>Ture to convert <cite>tf.matmul</cite> to <cite>nn.dense</cite>, else to <cite>nn.matmul</cite>.
The <cite>nn.dense</cite> op requires the data tensor to be non-transposed and weight tensor
to be transposed, may insert extra <cite>transpose</cite> to the original graph.</p>
</dd>
<dt>use_nt_batch_matmul<span class="classifier">bool = True</span></dt><dd><p>True to convert <cite>tf.batch_matmul</cite> to <cite>nn.batch_matmul</cite> strict to NT format
(transpose_a=False, transpose_b=True).</p>
</dd>
</dl>
</dd>
</dl>
</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The module that optimizations will be performed on.</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.nd.NDArray</em>) – Dict of converted parameters stored in tvm.nd.NDArray format</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_darknet">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_darknet</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">net</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dtype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'float32'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_darknet" title="永久链接至目标">¶</a></dt>
<dd><p>将Darknet模型转换为对应的relay Function。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>net</strong> (<em>Darknet net parameter</em>) – Darknet的网络结构。</p></li>
<li><p><strong>shape</strong> (<em>dict of str to tuple</em><em>, </em><em>optional</em>) – 计算图输入节点的数据形状</p></li>
<li><p><strong>dtype</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a><em> or </em><em>dict of str to str</em>) – 计算图输入节点的数据类型</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The relay module for compilation.</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.nd.NDArray</em>) – The parameter dict to be used by relay</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_pytorch">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_pytorch</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">script_module</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">input_infos</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">custom_convert_map</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default_dtype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'float32'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_parser_friendly_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">keep_quantized_weight</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_pytorch" title="永久链接至目标">¶</a></dt>
<dd><p>使用torchscipt形式加载PyTrch模型，并将其转换为对应的relay。模型配套的参数将被自动处理。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>script_module</strong> (<em>TopLevelTracedModule object</em>) – 基于TorchScripted的Pytorch计算图。注意：我们目前仅支持少许功能（如：torch.jit.trace(model, input)）。</p></li>
<li><p><strong>input_infos</strong> (<em>List of tuples</em>) – 它的样式可以是由[输入名称，(输入形状)]或[输入名称, (输入形状, 输入类型)]组成的列表或元组，代表计算图的输入形状和类型列表。在转换时需要使用相同的输入节点名称，因此请使用容易记忆的名称（如：input0，input1）。例如：[(‘input0’, (1, 2)), (‘input1’, (3, 4))] 或 [(‘input0’, ((1, 2), ‘int’), (‘input1’, ((3, 4), ‘float’)]。</p></li>
<li><p><strong>custom_convert_map</strong> (<em>Dictionary of str to Relay op</em>) – 一个与上述_convert_map具有相同格式的自定义算子转换图。</p></li>
<li><p><strong>default_type</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.10)"><em>str</em></a>) – The default dtype to use when type information is not provided by PyTorch.</p></li>
<li><p><strong>use_parser_friendly_name</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.10)"><em>bool</em></a>) – When True, replace ‘.’ with <a href="#id1"><span class="problematic" id="id2">`</span></a>_’ in a original parameter name.
The Relay text parser treats a variable name followed by a period as a tuple element access,
so a variable name like “dense.weight” cannot be parsed correctly.
Use this option when you want to run the AnnotateSpans pass on the imported module.</p></li>
<li><p><strong>keep_quantized_weight</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.10)"><em>bool</em></a>) – Return quantized weights and bias, rather than float ones. PyTorch stores quantized weights
in a custom format, so we cannot directly access 8 bit weights as Numpy arrays. We use
a PyTorch function to unpack quantized weights into float32 arrays and quantization
parameters. By default, we return float32 weights and rely on the QNN lowering and the
Relay constant folding pass to quantize weights at compile time. In BYOC use cases, however,
we cannot apply the constant folding pass on a QNN graph. If keep_quantized_weight is True,
we quantize weights in the frontend using a function that is equivalent to
qnn.op.quantize(…) operating on Numpy arrays.</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The module that optimizations will be performed on.</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.runtime.NDArray</em>) – Dict of converted parameters stored in tvm.runtime.ndarray format</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_caffe">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_caffe</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">init_net</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">predict_net</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dtype_dict</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_caffe" title="永久链接至目标">¶</a></dt>
<dd><p>将caffe模型转换为对应的relay Function。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>init_net</strong> (<em>caffe_pb2.NetParameter</em>) – caffemodel</p></li>
<li><p><strong>predict_net</strong> (<em>caffe_pb2.NetParameter</em>) – caffe prototxt</p></li>
<li><p><strong>shape_dict</strong> (<em>dict of str to int list/tuple</em>) – 模型输入节点的数据形状。</p></li>
<li><p><strong>dtype_dict</strong> (<em>dict of str to str</em>) – 模型输入节点的数据类型。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>mod</strong> (<em>tvm.IRModule</em>) – The relay module for compilation.</p></li>
<li><p><strong>params</strong> (<em>dict of str to tvm.NDArray</em>) – The parameter dict to be used by relay</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="tvm.relay.frontend.from_paddle">
<span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">from_paddle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">program_or_layer</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shape_dict</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">scope</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.from_paddle" title="永久链接至目标">¶</a></dt>
<dd><p>将PaddlePaddle模型转换为对应的Relay Function。</p>
<p>在PaddlePaddle中，Program或者TranslatedLayer代表PaddlePaddle模型的计算图，PaddlePaddle scope用来存储PaddlePaddle模型的所有权重。</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="tvm.relay.frontend.ChangeDatatype">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">tvm.relay.frontend.</span></span><span class="sig-name descname"><span class="pre">ChangeDatatype</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">src</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tvm.relay.frontend.ChangeDatatype" title="永久链接至目标">¶</a></dt>
<dd><p>需要改变Relay中数据类型时的应变手段。</p>
<p>This pass should be useful for users of the Bring Your Own Datatypes
framework.
TODO(&#64;gussmith23 &#64;hypercubestart) Add link to documentation when it exists</p>
<p>举例：</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">tvm.relay.testing.inception_v3</span> <span class="kn">import</span> <span class="n">get_workload</span>
<span class="n">mod</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">get_workload</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">change_dtype</span><span class="p">(</span><span class="n">mod</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">):</span>
    <span class="n">mod</span> <span class="o">=</span> <span class="n">ChangeDatatype</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">)(</span><span class="n">mod</span><span class="p">)</span>
    <span class="n">params</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">((</span><span class="n">p</span><span class="p">,</span> <span class="n">tvm</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">params</span><span class="p">[</span><span class="n">p</span><span class="p">]</span><span class="o">.</span><span class="n">numpy</span><span class="p">()</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">dst</span><span class="p">)))</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">params</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">mod</span><span class="p">,</span> <span class="n">params</span>

<span class="n">mod</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">change_dtype</span><span class="p">(</span><span class="n">mod</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="s2">&quot;float32&quot;</span><span class="p">,</span> <span class="s2">&quot;custom[posites2]32&quot;</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>src</strong> (<a class="reference internal" href="../runtime.html#tvm.runtime.String" title="tvm.runtime.String"><em>String</em></a>) – 原始数据类型名称，例如 “float “或 “posites2”（但不是 “float32 ” 或  “custom[posites2]32”）。</p></li>
<li><p><strong>dst</strong> (<a class="reference internal" href="../runtime.html#tvm.runtime.String" title="tvm.runtime.String"><em>String</em></a>) – 转换后数据类型名称，格式相同。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p><strong>mod</strong> – Module where all nodes of dtype <cite>src</cite> have been changed to have dtype
<cite>dst</cite>.</p>
</dd>
<dt class="field-odd">返回类型</dt>
<dd class="field-odd"><p>tvm.IRModule</p>
</dd>
</dl>
</dd></dl>

</div>


           </div>
           
          </div>
          

<footer>

    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="nn.html" class="btn btn-neutral float-right" title="tvm.relay.nn" accesskey="n" rel="next">下一个 <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="index.html" class="btn btn-neutral float-left" title="tvm.relay" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> 上一个</a>
      
    </div>

<div id="button" class="backtop"><img src="../../../../_static//img/right.svg" alt="backtop"/> </div>
<section class="footerSec">
    <div class="footerHeader">
      <ul class="d-flex align-md-items-center justify-content-between flex-column flex-md-row">
        <li class="copywrite d-flex align-items-center">
          <h5 id="copy-right-info">© 2020 Apache Software Foundation | All right reserved</h5>
        </li>
      </ul>

    </div>

    <ul>
      <li class="footernote">Copyright © 2020 The Apache Software Foundation. Apache TVM, Apache, the Apache feather, and the Apache TVM project logo are either trademarks or registered trademarks of the Apache Software Foundation.</li>
    </ul>

</section>
</footer>
        </div>
      </div>

    </section>

  </div>
  

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

  </body>
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-75982049-2', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>